import axios from 'axios'

const API_URL = process.env.VUE_APP_API_URL || 'http://localhost:3000/api'

const adminService = {
  // 用户管理
  async getUsers(page = 1, search = '') {
    await new Promise((resolve) => setTimeout(resolve, 500))
    return {
      users: [
        {
          id: 1,
          username: 'admin',
          email: 'admin@example.com',
          role: 'admin',
          status: 'active',
          createdAt: '2024-01-01',
        },
        {
          id: 2,
          username: 'user1',
          email: 'user1@example.com',
          role: 'user',
          status: 'active',
          createdAt: '2024-01-02',
        },
      ],
      totalPages: 1,
    }
  },
  async updateUser(userId, userData) {
    await new Promise((resolve) => setTimeout(resolve, 300))
    return { ...userData, id: userId }
  },
  async deleteUser(userId) {
    await new Promise((resolve) => setTimeout(resolve, 200))
    return true
  },
  // 歌曲管理
  async getSongs(page = 1, search = '') {
    await new Promise((resolve) => setTimeout(resolve, 500))
    return {
      songs: [
        {
          id: 1,
          title: '示例歌曲 1',
          artist: '艺术家 1',
          genre: '流行',
          status: 'published',
          uploadDate: '2024-01-01',
        },
        {
          id: 2,
          title: '示例歌曲 2',
          artist: '艺术家 2',
          genre: '摇滚',
          status: 'published',
          uploadDate: '2024-01-02',
        },
      ],
      totalPages: 1,
    }
  },
  async updateSong(songId, songData) {
    await new Promise((resolve) => setTimeout(resolve, 300))
    return { ...songData, id: songId }
  },
  async deleteSong(songId) {
    await new Promise((resolve) => setTimeout(resolve, 200))
    return true
  },
  // 系统设置
  async getSettings() {
    await new Promise((resolve) => setTimeout(resolve, 200))
    return {
      siteName: '听友音乐曲库管理系统',
      allowRegistration: true,
      maxUploadSize: 10,
      allowedFileTypes: ['mp3', 'wav', 'flac'],
      maintenanceMode: false,
    }
  },
  async updateSettings(settings) {
    await new Promise((resolve) => setTimeout(resolve, 300))
    return settings
  },
}

export { adminService }
